package com.chanjiedata.changbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.proto.MemberOuterClass;

import java.util.List;

public class MarchieActionAdapter extends BaseAdapter {

    private List< MemberOuterClass.my_partners_list.ActivationInfo> provinceBeanList;
    private LayoutInflater layoutInflater;
    private Context mContext;

    public MarchieActionAdapter(Context context, List< MemberOuterClass.my_partners_list.ActivationInfo> provinceBeanList) {
        this.provinceBeanList = provinceBeanList;
        mContext = context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return provinceBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return provinceBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.grid_view_item_layout, null);
            holder = new ViewHolder();
            holder.tv_h9_one = (TextView) convertView.findViewById(R.id.tv_h9_one);
            holder.tv_h9_two = (TextView) convertView.findViewById(R.id.tv_h9_two);
            holder.tv_one_progress = (TextView) convertView.findViewById(R.id.tv_one_progress);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
         MemberOuterClass.my_partners_list.ActivationInfo provinceBean = provinceBeanList.get(position);
        if (provinceBean != null) {

            setProData(
                    provinceBean,
                    holder.tv_h9_one,
                    holder.tv_h9_two,
                    holder.tv_one_progress
            );
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_h9_one;
        TextView tv_h9_two;
        TextView tv_one_progress;
    }


    private void setProData(
             MemberOuterClass.my_partners_list.ActivationInfo bean_one,
            TextView one,
            TextView two,
            TextView name_view
    ) {
        // 1.获取数据
        String total_stock = bean_one.getTotalStock();
        String activation = bean_one.getActivation();
        one.setText(activation);
        two.setText(total_stock);
        name_view.setText(bean_one.getName());
    }

}
